﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
    ViewData["Title"] = "生产管理";
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>生产管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/libs/scripts/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
    <script src="~/libs/scripts/layui-v2.5.6/layui/layui.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    <div class="layui-card">
        <div class="layui-card-header">
            <div class="layui-row">
                <div class="layui-col-md6">
                    <h2>生产管理</h2>
                </div>
                <div class="layui-col-md6" style="text-align: right;">
                    <button class="layui-btn" id="btnAdd">
                        <i class="layui-icon">&#xe654;</i> 新增生产工单
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <!-- 搜索栏 -->
            <form class="layui-form layui-form-pane" lay-filter="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">工单名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="orderName" placeholder="请输入工单名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn" lay-submit lay-filter="searchBtn">
                            <i class="layui-icon">&#xe615;</i> 搜索
                        </button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
            <!-- 数据表格 -->
            <table id="productionTable" lay-filter="productionTable"></table>
        </div>
    </div>
    <!-- 表格操作列模板 -->
    <script type="text/html" id="tableBar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
        layui.use(['table', 'form', 'layer'], function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.$;
            // 初始化表格
            table.render({
                elem: '#productionTable',
                url: '/Prouduction/ShowProdction',
                page: true,
                where: {},
                request: {
                    pageName: 'pageIndex',
                    limitName: 'pageSize'
                },
                cols: [[
                    {field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left', templet: function(d){ return d.id || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'orderCode', title: '工单编码', width: 120, templet: function(d){ return d.orderCode || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'orderName', title: '工单名称', width: 120, templet: function(d){ return d.orderName || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'orderState', title: '工单类型', width: 100, templet: function(d){ return d.orderState || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'sourceType', title: '来源类型', width: 100, templet: function(d){ return d.sourceType || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'orderNumber', title: '订单编号', width: 120, templet: function(d){ return d.orderNumber || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'documentStatus', title: '单据状态', width: 100, templet: function(d){ return d.documentStatus || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'productionCode', title: '产品编号', width: 120, templet: function(d){ return d.productionCode || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'productionName', title: '产品名称', width: 120, templet: function(d){ return d.productionName || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'specifications', title: '规格型号', width: 120, templet: function(d){ return d.specifications || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'unit', title: '单位', width: 80, templet: function(d){ return d.unit || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'orderCount', title: '工单数量', width: 100, templet: function(d){ return d.orderCount != null && d.orderCount !== '' ? d.orderCount : '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'demandDate', title: '需求日期', width: 120, templet: function(d){ return d.demandDate ? layui.util.toDateString(d.demandDate, 'yyyy-MM-dd') : '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'batchCode', title: '批次号', width: 120, templet: function(d){ return d.batchCode || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'customerCode', title: '客户编号', width: 120, templet: function(d){ return d.customerCode || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'customerName', title: '客户名称', width: 120, templet: function(d){ return d.customerName || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'supplierCode', title: '供应商编码', width: 120, templet: function(d){ return d.supplierCode || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'supplierName', title: '供应商名称', width: 120, templet: function(d){ return d.supplierName || '<span style="color:#bbb">暂无</span>'; }},
                    {field: 'commont', title: '备注', width: 200, templet: function(d){ return d.commont || '<span style="color:#bbb">暂无</span>'; }},
                    {title: '操作', toolbar: '#tableBar', width: 150, fixed: 'right'}
                ]]
            });
            // 搜索按钮点击事件
            form.on('submit(searchBtn)', function(data){
                table.reload('productionTable', {
                    where: data.field
                });
                return false;
            });
            // 新增按钮点击事件
            $('#btnAdd').on('click', function(){
                layer.open({
                    type: 2,
                    title: '新增生产工单',
                    area: ['1100px', '700px'],
                    content: '/Prouduction/AddProuductionView',
                    end: function(){
                        window.reloadProductionTable();
                    }
                });
            });
            // 表格工具条事件
            table.on('tool(productionTable)', function(obj){
                var data = obj.data;
                if(obj.event === 'edit'){
                    layer.open({
                        type: 2,
                        title: '编辑生产工单',
                        area: ['1100px', '700px'],
                        content: '/Prouduction/AddProuductionView?id=' + data.id,
                        end: function(){
                            window.reloadProductionTable();
                        }
                    });
                } else if(obj.event === 'del') {
                    layer.confirm('确定要删除这条生产工单吗？', function(index){
                        $.ajax({
                            url: '/Prouduction/DeleteProdction',
                            type: 'DELETE',
                            data: { id: data.id },
                            success: function(res){
                                layer.msg('删除成功');
                                obj.del();
                                layer.close(index);
                            },
                            error: function(xhr, status, error){
                                layer.msg('删除失败：' + xhr.responseText, {icon: 2});
                            }
                        });
                    });
                }
            });
            // 全局表格刷新函数，供iframe调用
            window.reloadProductionTable = function(){
                layui.table.reload('productionTable');
            }
        });
    </script>
</body>
</html>




